import { legacy_createStore as createStore } from 'redux';

const initState = {
  count: 99,
};

function countReducer(state = initState, action) {
  switch (action.type) {
    case 'add':
      return { ...state, count: state.count + action.payload };
    case 'des':
      return { ...state, count: state.count - action.payload };
    default:
      return state;
  }
}

export const addAction = (payload) => {
  return {
    type: 'add',
    payload,
  };
};

export const desAction = (payload) => {
  return {
    type: 'des',
    payload,
  };
};

const store = createStore(countReducer);

export default store;
